
import utils from "../../utils/util"
Page({
  data: {
  navState: 0,//导航状态
  shuju:null,
  zuixin:null,
  rege:null,
  times: 0 as any,
  sousuo:null as any,
  value:'', //搜索框
  geshou:null as any , //歌手
  ssnr:null as any, //搜索推荐
  showtime:true,
  haibao:null as any, //歌手海报
  },
  //监听滑块
  bindchange(e:any) {
  // console.log(e.detail.current)
  let index = e.detail.current;
  this.setData({
  navState:index
  })
  },
  //点击导航
  navSwitch: function(e:any) {
  // console.log(e.currentTarget.dataset.index)
  let index = e.currentTarget.dataset.index;
  this.setData({
  navState:index
  })

  
  },
 
  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function() {
 this.huoqu()
 this.setData({
times :utils.time(new Date()) 
 })
  },
 //输入监听
 confirmTap(e:any) {
 
  let a=e.detail
  if (a.length>0) {
    this.setData({
    value:a
  })
  }
  
  this.shihsi(a)
},
  //获取数据测试
  huoqu(){
//编辑音乐
    wx.request({
      url: 'http://localhost:3000/top/playlist/highquality?limit=6',
      method: "GET",
      success: (result :any) => {
          // console.log(result.data.playlists)
          this.setData({
           shuju:result.data.playlists
           
          })
      },
    }),
    //最新音乐
    wx.request({
      url: 'http://localhost:3000/personalized/newsong',
      method: "GET",
      success: (result :any) => {
          // console.log(result.data.result)
          this.setData({
            zuixin:result.data.result
           
          })
      },
    })
    //热歌
    wx.request({
      url:'http://localhost:3000/playlist/detail?id=3778678',
      method:'GET',
      success:(res :any)=>{
  // console.log(res.data.playlist.tracks);
  this.setData({
    rege:res.data.playlist.tracks.slice(0,20)
  })
      }
    })
    //热门搜索
    wx.request({
      url:'http://localhost:3000/search/hot',
      method:'GET',
      success:(res :any)=>{
  // console.log(res.data.result.hots);
  this.setData({
    sousuo:res.data.result.hots
  })
      }
    })

  },
  onSearch(e:any){
    let ab=e.detail
    console.log('搜索'+ ab);
    this.geshou(ab)
 

  },
  onCancel() {
    console.log("取消");
    
 this.setData({
   geshou:null,
   showtime:true
  
 })
  
  },
  onMyEvent: function(e:any) {
    let abc=e.detail
    this.setData({
      value:abc
    })
    this.geshou(abc)

},
geshou(val:string){
wx.request({
  url:`http://localhost:3000/cloudsearch?keywords=${val}&offset=1&limit=20`,
  method:"GET",
  success:(res:any)=>{
    // console.log(res.data.result.songs);
    this.setData({
      geshou:res.data.result.songs,
      showtime:false,
      ssnr:null
    })  
  }
}),
wx.request({
  url:`http://localhost:3000/search/multimatch?keywords=${val}`,
  method:"GET",
  success:(res:any)=>{
    console.log(res.data.result.artist[0]);
    this.setData({
      haibao:res.data.result.artist,
      showtime:false,
      ssnr:null
    }) 
  }
})
},
//获取海报

//时实获取数据
shihsi(val:string){
  if (val.length!==0) {
    wx.request({
  url:`http://localhost:3000/search/suggest?keywords=${val}&type=mobile`,
  method:"GET",
  success:(res:any)=>{
    console.log(res.data.result.allMatch);
    
   this.setData({
    ssnr:res.data.result.allMatch,
    showtime:false
   })   
  }
})
  }else{
    this.setData({
      ssnr:null,
      showtime:true
    })
  }
  

}



 })